<!DOCTYPE html>
<html lang="en">
<head th:include="certificateWeb/headFoot :: headerCss">
</head>
<link rel="stylesheet" href="/css/certificateWeb/trainStudentInfo.css">

<body id="body">
<style>
    
</style>
<main id="main">
    <section class="sec_1">
        <div class="div_2">
            <label class="label_title">培训学员信息表</label>
            <hr/>
            <form class="form-horizontal m-t" id="signupForm" enctype="multipart/form-data">
            <div id="info">
                <div class="div_3">
                    <label class="span_1">姓名<span style="color: #D52525">*</span>：</label>
                    <input id='name' type="text" value=""  placeholder="姓名" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">身份证号<span style="color: #D52525">*</span>：</label>
                    <input id='idNumber' type="text" value=""  placeholder="身份证号" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">手机号码<span style="color: #D52525">*</span>：</label>
                    <input id='mobile' type="text" value=""  placeholder="手机号码" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">培训类型<span style="color: #D52525">*</span>：</label>
                    <select id='type' class="form-control sel_1"/>
                        <option value='-1'>--请选择培训类型--</option>
                        <option value='师资'>师资</option>
                        <option value='考评员'>考评员</option>
                        <option value='考务技术员'>考务技术员</option>
                    </select>
                </div>
            </div>
            <div class="div_3">
                <label class="span_1">电子寸照<span style="color: #D52525">*</span>：</label>
                <button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload">
                    <i class="fa fa-cloud"></i>请上传JPG格式寸照
                </button>
                <input type="text" value="" style="opacity:0;width: 1px;" id="picAddress" name="picAddress"/>
                <span id="test"></span>
                <div style="clear: both"></div>
            </div>
            <div class="div_3">
                <button class="form-control but_1 send" type="submit">提交审核</button>
            </div>
            </form>
        </div>
        
        <div style="clear: both"></div>
    </section>
</main>

<script src="/lib/jquery/jquery.min.js"></script>
    <script src="/lib/jquery/jquery-migrate.min.js"></script>
    <script src="/js/layui/layui.js"></script>
    <script src="/js/plugins/layer/layer.min.js"></script>
    <script src="/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/js/plugins/validate/messages_zh.min.js"></script>
    <script src="/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
    
</body>
<script>
    $(function () {

        //通过文件路径截取名称
        function subFileName(fileUrl) {
            var index = fileUrl .lastIndexOf("\/");
            fileUrl  = fileUrl .substring(index + 1, fileUrl .length);
            return fileUrl
        }

        $('.send').click(function () {
            if($('#name').val()==""){
                layer.msg('姓名不能为空');
                return false;
            }
            if($('#idNumber').val()==""){
                layer.msg('身份证号码不能为空');
                return false;
            }
            if($('#mobile').val()==""){
                layer.msg('手机号不能为空');
                return false;
            }
            if($('#type').val()=="-1"){
                layer.msg('培训类型未选择');
                return false;
            }
            if($('#picAddress').val()==""){
                layer.msg('未上传照片');
                return false;
            }
        $.ajax({
            type: "POST",
            url: "/jzApi/trainSudentInfo/saveInfo",
            data: {
                name : $('#name').val(),
                idNumber :$('#idNumber').val(),
                mobile : $('#mobile').val(),
                type : $('#type').val(),
                picAddress :$('#picAddress').val()
            },
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    alert("提交成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    alert(data.msg);
                }
            }
        });

    });

        layui.use('upload', function () {
                var upload = layui.upload;
                //执行实例
                upload.render({
                    elem: '#btnUpload', //绑定元素
                    url: '/jzApi/utils/fileImprot', //上传接口
                    size: 1000,
                    accept: 'file',
                    done: function (r) {
                        $("#picAddress").val(r.data);
                        $("#test").html(subFileName(r.data));
                    },
                    error: function (r) {
                        layer.msg(r.msg);
                    }
                });
            });
        });
</script>
</html>